package com.wntms.ft.controller;

import com.wntms.ft.pojo.FareForm;
import com.wntms.ft.pojo.Index;
import com.wntms.ft.result.Result;
import com.wntms.ft.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/findIndex")
public class IndexFindController {
    @Autowired
    private IndexService indexService;

    @GetMapping("")
    public Result selectOrder() {
        Index index = indexService.selectOrder();
        if (index != null) {
            return Result.success(index, "查询成功");
        }
        return Result.error("查询失败");

    }

    @GetMapping("/findTotal")
    public Result findFareTotal(){
        List<FareForm> fareTotal = indexService.findFareTotal();
        HashMap<String, Object> hashMap = new HashMap<>();
        if (fareTotal != null) {
            ArrayList<String> x = new ArrayList<>();
            ArrayList<Object> y = new ArrayList<>();
            for (FareForm fareForm : fareTotal) {
                x.add(fareForm.getName());
                y.add(fareForm.getFare());
            }
            hashMap.put("x",x);
            hashMap.put("y",y);
            return Result.success(hashMap,"查询成功");
        }
        return Result.error("查询失败");
    }

}
